{extend name="public/base" /} 
{block name="style"}<link href="__LIB__/fileinput/css/fileinput.min.css" rel="stylesheet" /> {/block}
{block name="body"}
<div class="content-tabs">
	<ol class="breadcrumb">
		<li>
			<a href="{:url('index/index')}"><i class="fa fa-home"></i></a>
		</li>
		<li>
			<a href="{:url('index')}">优惠券管理</a>
		</li>
		<li><strong>新增优惠券</strong></li>
	</ol>
</div>
<div class="row">
	<div class="col-sm-12">
		<div class="ibox float-e-margins">
			<div class="ibox-content">
			<form id="myForm" class="form-horizontal m-t" method="post" action="{:url('add')}">
					<div class="form-group">
						<label class="col-sm-3 control-label">优惠类型：</label>
						<div class="input-group col-sm-4">
						<input type="radio" name="typeid" id="typeid" value="1" checked=""/> 代金券
						&nbsp;
						<input type="radio" name="typeid" id="typeid" value="2" /> 折扣券
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label">优惠券名称：</label>
						<div class="input-group col-sm-4">
							<input type="text" id="name" name="name" value="" placeholder="请输入优惠券名称" class="form-control" />
						</div>
					</div>
					<div class="form-group mz">
						<label class="col-sm-3 control-label">面值：</label>
						<div class="input-group col-sm-4">
							<input type="text" id="parvalue" name="parvalue" value="" placeholder="例如， 100" class="form-control" onkeyup="clearNoNums(this)" onafterpaste="this.value=this.value.replace(/[^\d]/g,'')"/>
							<label class="col-sm-3 control-label" style="position: absolute;text-align: left;">元</label>
						</div>
						<label class="col-sm-3 control-label"></label>
						<div class="input-group col-sm-4">
							收款时将抵扣指定的固定金额，但不找零。
						</div>
					</div>
					<div class="form-group zk" style="display: none;">
						<label class="col-sm-3 control-label">折扣：</label>
						<div class="input-group col-sm-4">
							<input type="text" id="discount" name="discount" value="" placeholder="例如，95" class="form-control" onkeyup="clearNoNum(this)" onafterpaste="this.value=this.value.replace(/[^\d]/g,'')"/>
							<label class="col-sm-3 control-label" style="position: absolute;text-align: left;">%</label>
						</div>
						<label class="col-sm-3 control-label"></label>
						<div class="input-group col-sm-4">
							95%表示收款时将抵扣应收金额的5%。
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label">使用条件：</label>
						<div class="input-group col-sm-9">
							<div class="row">
                                <div class="col-md-4">
									<input type="text" id="useconditions" name="useconditions" value="" placeholder="0.00" class="form-control" onkeyup="clearNoNums(this)" onafterpaste="this.value=this.value.replace(/[^\d]/g,'')"/>
                                </div>
                                <div class="col-md-3">
                                    <input name="is_over" id="is_over" type="checkbox"/> 可叠加使用
                                </div>
	                        </div>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label">有效期类型：</label>
						<div class="input-group col-sm-4">
                           	<select class="form-control" name="validity_type" id="validity_type">
								<option value="1">指定日期</option>
								<option value="2">设置天数</option>	
							</select>
						</div>
					</div>
					<div class="form-group yx">
						<label class="col-sm-3 control-label">有效日期：</label>
						<div class="input-group col-sm-9">
							<div class="row">
                                <div class="col-md-2">
									<input id='validity_starttime' style="width: 160px;" name='validity_starttime' value="" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true})"  type='text' placeholder="" class="form-control layer-date" />
                                </div>
                                <div class="col-md-2">
                              	 	<input id='validity_endtime'style="width: 160px;" name='validity_endtime' value=""  onclick="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true})"  type='text' placeholder="" class="form-control layer-date" />
                                </div>
	                        </div>
                			不论何时发放或领取，均要在有效日期范围内使用，其中开始日期对应时间为0点，结束日期对应时间为24点。
						</div>
					</div>
					<div class="form-group zd" style="display: none;">
						<label class="col-sm-3 control-label">天数：</label>
						<div class="input-group col-sm-4">
							<input type="text" id="validity_date" name="validity_date" value="" placeholder="0-365" class="form-control" onkeyup="clearNoNums(this)" onafterpaste="this.value=this.value.replace(/[^\d]/g,'')"/>
							从发放或领取时间开始计时，例如，有效天数为10天，如果3月2日领取，则过期时间为3月12日的24点。
						</div>
					</div>
					<div class="hr-line-dashed"></div>
					<div class="form-group">
						<div class="col-sm-4 col-sm-offset-3">							
							<button class="btn btn-primary" type="submit"><i class="fa fa-save"></i> 保存</button>&nbsp;&nbsp;
							<a href="{:url('index')}" class="btn btn-danger"><i class="fa fa-arrow-left"></i> 返回 </a>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
</div>
{/block} {block name="script"}
<script src="__JS__/jquery.form.js"></script>
<script src="__LIB__/datepicker/WdatePicker.js"></script>
<script src="__LIB__/validate/jquery.validate.min.js"></script>
<script src="__LIB__/validate/messages_zh.min.js"></script>
<script src="__LIB__/validate/add_validate.min.js"></script>
<script src="__LIB__/fileinput/js/fileinput.min.js"></script>
<script src="__LIB__/fileinput/js/locales/zh.js"></script>
<script src="__LIB__/ueditor/ueditor.config.js" type="text/javascript"></script>
<script src="__LIB__/ueditor/ueditor.all.js" type="text/javascript"></script>
<script>
	$(function() {
		$("#myForm").validate({
			rules: {
				name: "required",
				parvalue: "required"
			},
			messages: {
				name: ICON.error + "请输入优惠券名称",
				parvalue: ICON.error + "请输入面值",
			},
			submitHandler: function(form) {
				ajaxForm();
			}
		});
	});
</script>
<script>
	function clearNoNum(obj)
	{
		obj.value = obj.value.replace(/^[1-9]\d{2,}[\.]?\d*/,"100");
	   	obj.value = obj.value.replace(/[^\d.]/g,"");  //清除“数字”和“.”以外的字符
	   	obj.value = obj.value.replace(/^\./g,"");  //验证第一个字符是数字而不是.
	   	obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的.
	   	obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");	   
	}
		function clearNoNums(obj)
	{
	   	obj.value = obj.value.replace(/[^\d.]/g,"");  //清除“数字”和“.”以外的字符
	   	obj.value = obj.value.replace(/^\./g,"");  //验证第一个字符是数字而不是.
	   	obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的.
	   	obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");	   
	}
</script>
<script>
	$("input[name='typeid']").click(function(){
		var value = document.getElementById("typeid").checked;
		if(value == true){
			$(".mz").show();
			$(".zk").hide();
		}else if(value == false){
			$(".mz").hide();
			$(".zk").show();
		}
	})
	
	$("#validity_type").click(function(){
		var value = $("#validity_type").val();
		if(value == 1){
			$(".yx").show();
			$(".zd").hide();
		}else if(value == 2){
			$(".yx").hide();
			$(".zd").show();
		}
	})
</script>
{/block}